<template>
  <div class="main">
    <router-view></router-view>
    <div style="height:1.5rem" />
    <div>
      <van-tabbar v-model="active" active-color="#1890ff" :z-index="999">
        <van-tabbar-item icon="wap-home-o" to="/Home/HomeHot"
          >首页</van-tabbar-item
        >
        <van-tabbar-item icon="apps-o" to="/Categories/Categories"
          >分类</van-tabbar-item
        >
        <van-tabbar-item
          icon="chat-o"
          :badge="totalcount | BadgeFilter"
          to="/Notice/Index"
          >消息</van-tabbar-item
        >
        <van-tabbar-item icon="contact" to="/account/Account"
          >我的</van-tabbar-item
        >
      </van-tabbar>
    </div>
  </div>
</template>

<script>
import { mapMutations, mapGetters, mapActions } from "vuex";

var messageType = 5;
export default {
  name: "Main",
  data() {
    return {
      active: 0,
      totalcount: 0
    };
  },
  mounted() {
    this.socketApi.addcallback(this.getConfigResult, messageType);
  },
  destroyed() {
    this.socketApi.removecallback(this.getConfigResult);
  },
  computed: { ...mapGetters(["pushmessagetotal"]) },
  watch: {
    pushmessagetotal: {
      handler: function(val, oldval) {
        this.totalcount = val;
      },
      deep: true
    }
  },
  methods: {
    ...mapActions(["ClearAllUser", "ClearAllRole"]),
    ...mapMutations(["SET_PushmessageDetail"]),
    getConfigResult(res) {
      let resmsg = res;
      this.SET_PushmessageDetail(resmsg);
      this.totalcount =
        resmsg.UserMailCount + resmsg.UserMessageCount + resmsg.UserFormCount;

      let clearcache = resmsg.Clearcache;

      if (clearcache.indexOf("Base_User") != -1) {
        this.ClearAllUser();
      }
      if (clearcache.indexOf("Base_Role") != -1) {
        this.ClearAllRole();
      }
    }
  }
};
</script>
